package com.xyz.tasks.controller;

import com.free.common.vo.ResultModel;
import com.free.exception.SystemException;
import com.free.utils.DateUtils;
import com.xyz.domain.table.SLottery;
import com.xyz.tasks.bf.LotteryGenBf;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Date;

@Controller
public class TaskGenController {

    @Autowired
    LotteryGenBf genBf;

    @RequestMapping(value = "/genPeriod")
    @ResponseBody
    public ResultModel genLotteryPeriod(String lotteryId, String dateInfo) throws SystemException {
        if(StringUtils.isEmpty(lotteryId) || StringUtils.isEmpty(dateInfo)){
            throw new SystemException("非法请求");
        }
        Date date = DateUtils.convert2Date(dateInfo, DateUtils.FormatEnum.yyyy_MM_dd);
        SLottery lotteryInfo = genBf.lotteryInfo(lotteryId);
        return genBf.genLottery(lotteryInfo, date);
    }

}
